export default class Song {
  constructor ({ id, mid, singer, name, album, duration, image, url }) {
    this.songid = id
    this.songmid = mid
    this.singer = singer
    this.songname = name
    this.albumname = album
    this.duration = duration
    this.image = image
    this.filename = `C400${this.songmid}.m4a`
    this.url = url
  }
}
export const createSong = musicData => {
  return new Song({
    id: musicData.songid,
    mid: musicData.songmid,
    singer: filterSinger(musicData.singer),
    name: musicData.songname,
    album: musicData.albumname,
    duration: musicData.interval,
    image: `https://y.gtimg.cn/music/photo_new/T002R300x300M000${musicData.albummid}.jpg?max_age=2592000`,
    url: `http://ws.stream.qqmusic.qq.com/${musicData.songid}.m4a?fromtag=46`
  })
}
// 拼接多名歌手名称
export const filterSinger = singer => {
  if (!singer) {
    return ''
  }
  const ret = singer.reduce((pre, cur) => {
    pre.push(cur.name)
    return pre
  }, [])
  return ret.join('/')
}
